<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var a = {
        username:'frank',
        friends:['tom','jack'],
        other:{
            first:'111',
            second:'2222'
        }
    }
var b = {

};
    var cc = ['a','bb'];
        b['username'] = a['username'];
        //如果a['friends']是一个数组
//        b['friends'] = a['friends'];


//        b['friends'] = [];//新赋值一个空数组，目的是，让当前数组有一个自己的空间，与a的friends没有关系
//    b['friends'][0] = a['friends'][0];
//    b['friends'][1] = a['friends'][1];

    function deepCopyObject(from,to){
        var to = to||{};
        for (var i in from){
            if (from[i].constructor ===  Array  ||from[i].constructor === Object){
                if (from[i].constructor ===  Array)to[i] = [];//新的内
                if (from[i].constructor ===  Object)to[i] = {};//新的内
              deepCopyObject(from[i],to[i])
            } else {
                to[i] = from[i];
            }
        }
        return to;
    }

    var r = deepCopyObject(a,b);

</script>
</body>
</html>